<template>
	<view class="login">
		<view class="login_box1"> 注册天气预警账号 </view>
		<view class="login_box2">
			<input class="login_box2_input" v-model="account" type="text" placeholder="请输入账号"
				@input="isButton(account, password)" />
		</view>
		<view class="login_box3">
			<input class="login_box2_input" v-model="password" password="true" placeholder="请输入密码"
				@input="isButton(account, password)" />
		</view>
		<view class="login_box4">
			<view v-if="!isButtons">
				<button class="btn" type="primary" disabled="true">注册</button>
			</view>
			<view v-if="isButtons">
				<button class="btn" type="primary" @click="go">注册</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				password: '',
				account: '',
				isButtons: false
			}
		},
		onLoad() {
			// this.aaa()
		},
		methods: {
			zhuce() {
				uni.navigateTo({
					url: "../zhuce/zhuce",
				});
			},
			isButton(a, b) {
				if (a.length != 0 && b.length != 0) {
					this.isButtons = true;
					console.log(this.isButtons);
				}
				if (a.length == 0 || b.length == 0) {
					this.isButtons = false;
					console.log(this.isButtons);
				}
			},
			async go() {
				console.log(this.password)
				uni.showLoading({
					title: "请稍后",
				});
				let {
					result
				} = await this.$store.state.user.add({
					userName: this.account,
					passWord: this.password
				}).catch((res) => {
					uni.hideLoading();
					uni.showToast({
						title: "用户名重复",
						duration: 2000,
						icon: "error",
					});
				})
				uni.hideLoading();
				uni.showToast({
					title: "注册成功",
					duration: 2000,
					icon: "success",
				});
				setTimeout(() => {
					uni.navigateBack({
						delta: 1, //返回层数，2则上上页
					})
				}, 2000) //一秒钟打印出111
			},
			async aaa() {
				// promise方式
				uniCloud.callFunction({
						name: 'test',
						data: {
							a: 1
						}
					})
					.then(res => {
						console.log(res)
					});
				let res = await this.$store.state.user.get()
				console.log(res)
			}
		}
	}
</script>

<style>
	@import "../../common/css/index.css";
</style>
